﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

public partial class cn_index : System.Web.UI.Page
{
    protected string postTitle = "", postContent="";
    protected int postSelect = 1;
    protected void Page_Load(object sender, EventArgs e)
    {

        GetPostInfo();
        if (Session["UserName"] != null)
        {
            ltrTips.Visible = true;
            tabLogin.Visible = false;
            ltrTips.Text = "<div class=\"rightbox_div rightbox_divsure rightbox_div100104\" style=\"height:110px; line-height:35px;\"><strong>您好！" + Session["UserName"].ToString() + "</strong><bR /><a href=\"login.aspx\">[会员业务系统]</a><a href=\"forgetPwd.aspx\" class=\"a_13\">[密码修改]</a><bR /><a href=\"informations.aspx\">[修改资料]</a><a  class=\"a_14\" href=\"logout.aspx\">[安全退出]</a></div>";
        } 
        else
        {
            ltrTips.Visible = false;
            tabLogin.Visible = true;
        }
    }

    protected void GetPostInfo()
    {

        string sql1 = "select IsOpen,Title,Content from Whir_U_SinglePage where TypeID=88";
        DataTable dt1 = Whir.SQLServerDAL.DbHelperSQL.Query(sql1).Tables[0];
        if (dt1.Rows.Count > 0 && dt1 != null)
        {
            string IsOpen = dt1.Rows[0]["IsOpen"].ToString();
            if (IsOpen == "是")
            {

                postTitle = dt1.Rows[0]["Title"].ToString();
                postContent = dt1.Rows[0]["Content"].ToString();
                
            }
            else
            {
                postSelect = 0;
            }
        }

        
    }

    protected string GetZtactiveList(string TypeID,string  TopNum,int length)
    {
        string sql = "select top " + TopNum + " Title,Whir_U_News_PID,TypeID from Whir_U_News where TypeID=" + TypeID + " order by CreateDate desc";
        string mode = "ztactive";
        if (TypeID == "67" || TypeID == "74"||TypeID=="83"||TypeID=="79")
        {
            mode = "index";
        }
        System.Text.StringBuilder sb = new StringBuilder();
        System.Data.DataTable dt = Whir.SQLServerDAL.DbHelperSQL.Query(sql).Tables[0];
        if (dt != null && dt.Rows.Count > 0)
        {
            foreach (System.Data.DataRow dr in dt.Rows)
            {
                string title = dr["Title"].ToString();
                string id = dr["Whir_U_News_PID"].ToString();
                string _TypeID = dr["TypeID"].ToString();
                sb.AppendFormat("<li><a title=\"{0}\"  href=\"news_info.aspx?id={1}&mode=" + mode + "&cid={2}\">" + Whir.Common.WebHelper.StringHelper.CutString(dr["Title"].ToString(), length) + "</a></li>", title, id, _TypeID);
            }
        }

        return sb.ToString();
    }


    protected string GetNewsList(string TypeID, string TopNum,int length)
    {
        string sql = "select top " + TopNum + " Title,Whir_U_News_PID,TypeID,IsNew,CreateDate from Whir_U_News where TypeID=" + TypeID + " or TypeID in (select ColumnID from Whir_Column where ParentId=" + TypeID + ") order by CreateDate desc";
        System.Text.StringBuilder sb = new StringBuilder();
        System.Data.DataTable dt = Whir.SQLServerDAL.DbHelperSQL.Query(sql).Tables[0];
        if (dt != null && dt.Rows.Count > 0)
        {
            foreach (System.Data.DataRow dr in dt.Rows)
            {
                string title = dr["Title"].ToString();
                string id = dr["Whir_U_News_PID"].ToString();
                string _TypeID = dr["TypeID"].ToString();
                string IsNew = dr["IsNew"].ToString();
				string str="";
				if(IsNew=="是")
				{
				     str="class=\"aimg_checknew\"";
				}
                string CreateDate=Convert.ToDateTime(dr["CreateDate"].ToString()).ToString("MM-dd");
                sb.AppendFormat("<li><span>{3}</span><a {4}  title=\"{0}\"  href=\"news_info.aspx?id={1}&mode=&cid={2}\">" + Whir.Common.WebHelper.StringHelper.CutString(dr["Title"].ToString(), length) + "</a></li>", title, id, _TypeID, CreateDate,str);
            }
        }

        return sb.ToString();
    }


    protected string GetTopNewsList(string TypeID, string TopNum)
    {
        string str = "";
        int length=22;
        string sql = "select top " + TopNum + " Title,Whir_U_News_PID,TypeID,CreateDate from Whir_U_News where TypeID=" + TypeID + " or TypeID in (select ColumnID from Whir_Column where ParentId=" + TypeID + ") order by CreateDate desc";
        System.Text.StringBuilder sb = new StringBuilder();
        System.Data.DataTable dt = Whir.SQLServerDAL.DbHelperSQL.Query(sql).Tables[0];
        if (dt != null && dt.Rows.Count > 0)
        {
            for(int i=0;i<dt.Rows.Count;i++)
            {
                if (i == 0)
                {
                    str = "class=\"cenbox_ul_li\"";
                    length=24;
                }
                else
                {
                    str = "";
                    length = 30;
                }
                string title = dt.Rows[i]["Title"].ToString();
                string id = dt.Rows[i]["Whir_U_News_PID"].ToString();
                string _TypeID = dt.Rows[i]["TypeID"].ToString();
                string CreateDate = Convert.ToDateTime(dt.Rows[i]["CreateDate"].ToString()).ToString("MM-dd");
                if (i == 0)
                {
                    sb.AppendFormat("<li {3}><a title=\"{0}\"   href=\"news_info.aspx?id={1}&mode=&cid={2}\">" + Whir.Common.WebHelper.StringHelper.CutString(dt.Rows[i]["Title"].ToString(), length) + "</a></li>", title, id, _TypeID,  str);
                }
                else
                {
                    sb.AppendFormat("<li {4}><span>{3}</span><a title=\"{0}\"  href=\"news_info.aspx?id={1}&mode=&cid={2}\">" + Whir.Common.WebHelper.StringHelper.CutString(dt.Rows[i]["Title"].ToString(), length) + "</a></li>", title, id, _TypeID, CreateDate, str);
                }
            }
        }

        return sb.ToString();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Session["CheckCode"] == null)
        {
            Whir.Common.WebHelper.JsHelper.Alert(Page, "  验证码过期，请点击刷新  ");
            return;
        }

        //判断验证码
        if (this.checkedCode.Value != Session["CheckCode"].ToString())
        {
            Whir.Common.WebHelper.JsHelper.Alert(Page, "验证码不正确!");

            return;
        }
        //end
        Session["CheckCode"] = null;

        bool IsCanSQLInjection = Whir.Common.WebHelper.NetRequest.FilterSql(txtUsername.Value);
        bool IsCanSQLInjection2 = Whir.Common.WebHelper.NetRequest.FilterSql(txtPassword.Value);

        if (IsCanSQLInjection && IsCanSQLInjection2)
        {
            string sql = string.Format("select IsCheck,LoginName,MemberPwd from Whir_U_Users where LoginName='{0}' and MemberPwd='{1}'", txtUsername.Value, txtPassword.Value);
            DataSet ds = Whir.SQLServerDAL.DbHelperSQL.Query(sql);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                string IsCheck = ds.Tables[0].Rows[0]["IsCheck"].ToString();
                if (IsCheck.Trim() == "是")
                {
                    Session["UserName"] = ds.Tables[0].Rows[0]["LoginName"].ToString();

                    Whir.Common.WebHelper.JsHelper.redirect(this.Page, "登录成功!", "login.aspx");
                }
                else
                {
                    Whir.Common.WebHelper.JsHelper.Alert(Page, "您好，该帐号正在审核中，如有疑问请与我们联系，谢谢！");
                }
            }
            else
            {
                Whir.Common.WebHelper.JsHelper.Alert(Page, "登录失败！帐号或密码错误！请重新输入！");
            }
        }
        else
        {
            Whir.Common.WebHelper.JsHelper.Alert(Page, "登录失败！帐号或密码错误！请重新输入！");
        }
    }
}
